package com.next.androidintentlibrary;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.app.Context;
import ohos.bundle.BundleInfo;
import ohos.bundle.IBundleManager;
import ohos.rpc.RemoteException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class CalendarIntents {
    private Context context;
    private Intent intent;
    private ArrayList<HashMap<String, Object>> items;
    private IBundleManager bundleManager;

    private CalendarIntents(Context context)
    {
        this.context = context;
    }

    public static CalendarIntents from(Context context)
    {
        return new CalendarIntents(context);
    }

    public CalendarIntents openCalendar()
    {
        intent = new Intent();
        intent.setAction("android.intent.action.MAIN");
        intent.addEntity("android.intent.category.APP_CALENDAR");
        intent.setFlags(Intent.FLAG_ABILITY_NEW_MISSION);
        return this;
    }

    public Intent build()
    {
        return intent;
    }

    private void startAbility(Intent intent)
    {
        if (!(context instanceof Ability))
        {
            intent.addFlags(Intent.FLAG_ABILITY_NEW_MISSION);
        }
        context.startAbility(intent,0);
    }

    public void show()
    {
        startAbility(build());
    }
}
